Рассмотрим этот фрагмент кода, который пытается получить цвет темы из локального хранилища устройства iOS:
var color = UserDefaults.standard.string(forKey: "themeColor")! print(color)
Ответ: Первая строка извлекает цвет темы из user defaults. Этот метод, однако, возвращает optional (поскольку themeColor может быть не определен). Если ключ не найден, возвращается nil, что приводит к крашу:
fatal error: unexpectedly found nil while unwrapping an Optional value
Это происходит потому, что в первой строке используется ! для force unwrap optional, которое теперь nil. Force unwrapping должно использоваться только тогда, когда вы на 100% уверены, что значение не nil.
Чтобы исправить это, вы можете использовать optional binding для проверки, найдено ли значение для ключа:
if let color = defaults.stringForKey("themeColor") { print(color)}
Рассмотрим этот фрагмент кода, который пытается получить цвет темы из локального хранилища устройства iOS:
var color = UserDefaults.standard.string(forKey: "themeColor")! print(color)
Ответ: Первая строка извлекает цвет темы из user defaults. Этот метод, однако, возвращает optional (поскольку themeColor может быть не определен). Если ключ не найден, возвращается nil, что приводит к крашу:
fatal error: unexpectedly found nil while unwrapping an Optional value
Это происходит потому, что в первой строке используется ! для force unwrap optional, которое теперь nil. Force unwrapping должно использоваться только тогда, когда вы на 100% уверены, что значение не nil.
Чтобы исправить это, вы можете использовать optional binding для проверки, найдено ли значение для ключа:
if let color = defaults.stringForKey("themeColor") { print(color)}
A leaked Telegram discussion by 50 so-called crypto influencers has exposed the extraordinary steps they take in order to profit on the back off unsuspecting defi investors. According to a leaked screenshot of the chat, an elaborate plan to defraud defi investors using the worthless “$Few” tokens had been hatched. $Few tokens would be airdropped to some of the influencers who in turn promoted these to unsuspecting followers on Twitter.
To pay the bills, Mr. Durov is issuing investors $1 billion to $1.5 billion of company debt, with the promise of discounted equity if the company eventually goes public, the people briefed on the plans said. He has also announced plans to start selling ads in public Telegram channels as soon as later this year, as well as offering other premium services for businesses and users.
Библиотека мобильного разработчика | Android iOS Swift Retrofit Moshi Chuck from it